/**
 * Author  zxy
 * Date  2023/6/21 下午 3:41
 */
class Node {
    String data;
    Node pre;
    Node next;

    Node (String data) {
        this.data = data;
        pre = null;
        next = null;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public Node getPre() {
        return pre;
    }

    public void setPre(Node pre) {
        this.pre = pre;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }
}

public class DoubleLinked {

    Node head;
    Node tail;

    DoubleLinked () {
        head = null;
        tail = null;
    }

    public Node getHead() {
        return head;
    }

    public Node getTail() {
        return tail;
    }

    public void addHead (Node node){
        if (head == null) {
            head = node;
            tail = node;
        }
        else {
            node.next = head;
            head.pre = node;

            head = node;
        }
    }

    public void addTail (Node node){
        if (head == null) {
            head = node;
            tail = node;
        }
        else {
            tail.next = node;
            node.pre = tail;

            tail = node;
        }
    }

    public void delHead() {
        if (head == null) {
            return ;
        }

        if (head.next == null) {
            head = null;
            tail = null;
        }
        else {
            head = head.next;
            head.pre = null;
        }
    }

    public void delTail() {
        if (tail == null) {
            return ;
        }

        if (tail.pre == null) {
            head = null;
            tail = null;
        }
        else {
            tail = tail.pre;
            tail.next = null;
        }
    }
}